'use strict';

const Controller = require('egg').Controller;

class GoodsController extends Controller {
  // 商品查询，可以设置查询区间
  async index() {
    const { ctx } = this;
    var data = await ctx.service.goods.find(ctx.query);
    const {goods,total} = data
    ctx.cookies.set("name","cheng",{
      httpOnly:true
    })
    ctx.body ={
      code:200,
      res:goods,
      total,
      msg:"商品首页"
    }
  };
  // 价格升降序排序查询
  async sortPrice() {
    const { ctx } = this;
    var data = await ctx.service.goods.sort(ctx.query);
    const {goods,total} = data
    ctx.body ={
      code:200,
      res:goods,
      total,
      msg:"商品价格过滤"
    }
  }
}

module.exports = GoodsController;
